package com.nari.common.log.service;

import com.nari.common.log.enums.RstType;
import com.nari.system.api.RemoteRstLogService;
import com.nari.system.api.domain.RstRequest;
import com.nari.system.api.domain.SysRstLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.nari.system.api.RemoteLogService;
import com.nari.system.api.domain.SysOperLog;

import java.util.UUID;

/**
 * 异步调用日志服务
 * 
 * @author nari
 */
@Service
public class AsyncLogService
{
    @Autowired
    private RemoteLogService remoteLogService;

    @Autowired
    private RemoteRstLogService remoteRstLogService;

    /**
     * 保存系统日志记录
     */
    @Async
    public void saveSysLog(SysOperLog sysOperLog)
    {
        remoteLogService.saveLog(sysOperLog);
    }

    /**
     * 保存报文日志记录
     */
    @Async
    public void saveRstLog(SysRstLog sysRstLog)
    {

        remoteRstLogService.saveRstLog(sysRstLog);
    }

    /**
     * 保存报文日志记录
     */
    @Async
    public void saveRstLog(RstType rstType, RstRequest rstRequest)
    {
        SysRstLog sysRstLog = new SysRstLog();
       /* String uuid = UUID.randomUUID().toString().replaceAll("\\-", "");
        sysRstLog.setId(uuid);*/
        sysRstLog.setTranId(rstRequest.getTranId());
        sysRstLog.setTranName(rstRequest.getTranName());
        sysRstLog.setTaxpayer(rstRequest.getTaxpayer());
        sysRstLog.setTranSEQ(rstRequest.getTranSeq());
        sysRstLog.setType(rstType.getLogType());
        sysRstLog.setCreateTime(rstRequest.getCreateTime());
        sysRstLog.setStatus(rstRequest.getStatus());
        sysRstLog.setRemark("");//备注待赋值
        //sysRstLog.setcData(rstRequest.getcData());

        remoteRstLogService.saveRstLog(sysRstLog);
    }
}
